package com.dongnam.quanly.web.audit;

import java.io.Serializable;
import java.sql.Timestamp;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.event.ActionEvent;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dongnam.quanly.common.ActionCategory;
import com.dongnam.quanly.common.ActionType;
import com.dongnam.quanly.common.ObjectType;
import com.dongnam.quanly.common.ScreenId;
import com.dongnam.quanly.common.model.AuditTrailLog;

@ManagedBean(name = "AuditBean")
@ViewScoped
public class AuditBean implements Serializable {
	private static final long serialVersionUID = 1L;

	private static Logger logger = LoggerFactory.getLogger(AuditBean.class);

	private Timestamp fromDate;
	private Timestamp toDate;
	private String actioneeName;
	private String actioneeIp;
	private ScreenId screenId;
	private ActionCategory actionCategory;
	private ActionType actionType;
	private String result;
	private ObjectType object;
	private String objectId;
	private String cause;
	private String originVal;
	private String newVal;
	// private String details;

	private LazyAuditDataModel model;

	private AuditTrailLog selectedLog;

	public AuditBean() {
	}

	public void listenSearch(ActionEvent actionEvent) {
		logger.debug("listenSearch");
		if (model == null) {
			model = new LazyAuditDataModel();
		}
		model.init(this);
	}

	public AuditTrailLog getSelectedLog() {
		return selectedLog;
	}

	public void setSelectedLog(AuditTrailLog selectedLog) {
		this.selectedLog = selectedLog;
	}

	public Timestamp getFromDate() {
		return fromDate;
	}

	public void setFromDate(Timestamp fromDate) {
		this.fromDate = fromDate;
	}

	public Timestamp getToDate() {
		return toDate;
	}

	public void setToDate(Timestamp toDate) {
		this.toDate = toDate;
	}

	public String getActioneeName() {
		return actioneeName;
	}

	public void setActioneeName(String actioneeName) {
		this.actioneeName = actioneeName;
	}

	public String getActioneeIp() {
		return actioneeIp;
	}

	public void setActioneeIp(String actioneeIp) {
		this.actioneeIp = actioneeIp;
	}

	public ScreenId getScreenId() {
		return screenId;
	}

	public void setScreenId(ScreenId screenId) {
		this.screenId = screenId;
	}

	public ActionCategory getActionCategory() {
		return actionCategory;
	}

	public void setActionCategory(ActionCategory actionCategory) {
		this.actionCategory = actionCategory;
	}

	public ActionType getActionType() {
		return actionType;
	}

	public void setActionType(ActionType actionType) {
		this.actionType = actionType;
	}

	public ObjectType getObject() {
		return object;
	}

	public void setObject(ObjectType object) {
		this.object = object;
	}

	public String getObjectId() {
		return objectId;
	}

	public void setObjectId(String objectId) {
		this.objectId = objectId;
	}

	public String getOriginVal() {
		return originVal;
	}

	public void setOriginVal(String originVal) {
		this.originVal = originVal;
	}

	public String getNewVal() {
		return newVal;
	}

	public void setNewVal(String newVal) {
		this.newVal = newVal;
	}

	public String getCause() {
		return cause;
	}

	public void setCause(String cause) {
		this.cause = cause;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	// public String getDetails() {
	// return details;
	// }
	//
	// public void setDetails(String details) {
	// this.details = details;
	// }

	public LazyAuditDataModel getModel() {
		return model;
	}

	public void setModel(LazyAuditDataModel model) {
		this.model = model;
	}

	public boolean isExecute() {
		return (selectedLog.getActionType().equals(ActionType.EXECUTE));
	}

	public void clear() {
		setFromDate((Timestamp) null);
		setToDate((Timestamp) null);
		setActioneeName("");
		setActioneeIp("");
		setScreenId((ScreenId) null);
		setActionCategory((ActionCategory) null);
		setActionType((ActionType) null);
		setResult("");
		setObject((ObjectType) null);
		setObjectId("");
		setCause("");
		if (model != null)
			model.init(this);
	}

}
